/*
 * Copyright 2010 Michael Nitsche
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package de.mnit.basis.swt.grafik.icon;


import de.mnit.basis.fehler.Fehler;
import de.mnit.basis.fehler.system.F_Sys_Datei;
import de.mnit.basis.grafik.IconZugriff;
import de.mnit.basis.swt.grafik.Bild_SWT;
import de.mnit.basis.swt.grafik.S_Bild_SWT;
import de.mnit.basis.swt.grafik.S_SWT_Hat_Bild;

/*
 * Es muß immer ein neues Bild vergeben werden, denn die Bilder werden teils automatisch freigegeben!
 */
public class Icon implements S_SWT_Hat_Bild {

	private final String jarpfad;
	private S_Bild_SWT bild=null;


	public Icon(int groesse, String gruppe, String dateiname) {
		this.jarpfad=IconZugriff.gPfad(groesse,gruppe,dateiname);
	}

	public Icon(String jarpfad) {
		this.jarpfad=jarpfad;
	}


	public S_Bild_SWT gBild() {
		if(this.bild==null)
			try {
				this.bild=Bild_SWT.neu(IconZugriff.gStream(jarpfad));
			}
			catch(F_Sys_Datei e) {
				Fehler.zeig(e);
			}
		return this.bild.kopie(); //TODO Prüfen ob neu laden oder kopieren schneller/besser ist.
	}

}
